package com.itheima_2;

import java.lang.reflect.Field;

public class RFilectDemo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
       //meothd1();
        //meothd2();
        Class aClass = Class.forName("com.itheima_2.Student");
        //想要获取的必须存在且必须是public修饰的
        Field name = aClass.getField("name");
        Field money = aClass.getDeclaredField("money");
        System.out.println(money);
        System.out.println(name);
    }

    public static void meothd2() throws ClassNotFoundException {
        Class aClass = Class.forName("com.itheima_2.Student");
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);
        }
    }

    public static void meothd1() throws ClassNotFoundException {
        Class aClass = Class.forName("com.itheima_2.Student");
        Field[] fields = aClass.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }
    }
}
